package cn.lanqiao.blog.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.lanqiao.blog.vo.MessageVO;
import cn.lanqiao.blog.service.MessageService;
import cn.lanqiao.blog.utils.Result;

@RestController
@RequestMapping("message")
public class MessageController {
	
	@Autowired
	private MessageService messageService;

	//获取和其他用户的最新留言列表
	@PostMapping("getNewMessage")
	public Result getNewMessage(Integer userId){
		List<MessageVO> list = messageService.getMessageList(userId);
		return Result.success(list);
	}
	//获取对话列表
	@RequestMapping("getTalk")
	public Result getAllMessage(Integer userId,Integer withUserId){
		List<MessageVO> list = messageService.getTalkList(userId,withUserId);
		return Result.success(list);
	}
	//添加留言
	@RequestMapping("save")
	public Result  addMessage(MessageVO message) {
		messageService.saveMessage(message);
		return Result.success(null);
	}
	//删除留言
	@PostMapping("delete")
	public Result deleteMessage(Integer userId,Integer withUserId) {
		 messageService.deleteMessage(userId,withUserId);
		 return Result.success(null);
		 
	}

	
}
